<template>
	<view class="page">
		<view>
			
			<woods-coupon @btnBack="btnBack" :list='list' :type="type"></woods-coupon>
			
			<!-- <view class="nothing" v-if="list.length==0">
				- 暂无数据 -
			</view> -->
			<no-data v-if="list.length==0"/>
		</view>
		 
	 </view>
</template>

<script>
	import woodsCoupon from "@/components/woods-coupon.vue"
	 
	import {mapState,mapActions } from "vuex";
	import pageing from "@/mixins/pageing.js"
	import {goodsCouponAPI,couponTakeAPI} from "@/api/appointment.js"
	export default {
		mixins:[pageing],
		components:{woodsCoupon },
		data() {
			return {
				id:0, 
				type:0,
				list:[],
				
			}
		},
		computed:{
			 ...mapState("select", ["city"]),
		},
		onLoad(option) {
			if(option.type){//0员工1.商户2.商品
				this.id=option.id
				this.type=option.type
			}
			this.getlist()
		},
		
		methods: {
			btnBack(item){
				 
				couponTakeAPI(this.type, {templateId:item.id}).then(res=>{
					uni.showToast({
						title:'领取成功'
					})
					this.list=[]
					this.getlist()
				})
			},
			getlist(){
				var data={}
				if(this.type==0){
					data.staffId=this.id
				}else if(this.type==1){
					data.merchantId=this.id
				} 
				goodsCouponAPI(this.type, data).then(res=>{
 					this.list = this.list.concat(res.data);
					
				})
			},
			topChange(n){
				this.topSign=n
				// this.page=1
				// this.list=[]
				// this.$refs.waterfallsFlowRef.refresh();
				// this.getlist()
			},
			 
		}
	}
</script>

<style scoped lang="scss">
.page{
	background: #F8F8F8;
	min-height: 100vh;
	 
}
</style>
